package com.ushine.web.template.validation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ushine.web.template.validation.mapper.ValidationAndRoleMapper;
import com.ushine.web.template.validation.model.ValidationAndRoleDO;
import com.ushine.web.template.validation.service.IValidationAndRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotEmpty;
import java.util.Collection;
import java.util.List;

/**
 * @Author: yls
 * @Date 2022/3/18 10:40
 * @Description: 关联数据查询
 * @Version 1.0
 **/
@Validated
@Service
public class ValidationAndRoleServiceImpl extends ServiceImpl<ValidationAndRoleMapper, ValidationAndRoleDO>
        implements IValidationAndRoleService {

    @Override
    @Transactional(readOnly = true)
    public List<ValidationAndRoleDO> listValidationAndRoles(@NotEmpty(message = "id集合不能为空")Collection<Long> ids) {
        return listByIds(ids);
    }

    @Override
    @Transactional(readOnly = true)
    public Integer countValidationAndRole(@NotEmpty(message = "id集合不能为空")Collection<Long> ids) {
        LambdaQueryWrapper<ValidationAndRoleDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(ValidationAndRoleDO::getValidationId, ids);
        return count(lambdaQueryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean batchDeleteValidationAndRole(@NotEmpty(message = "删除的数据id集合不能为空")Collection<Long> ids) {
        return removeByIds(ids);
    }
}
